home *** CD-ROM | disk | FTP | other *** search
- Path: news.magmacom.com!not-for-mail
- From: ezust@mag1.magmacom.com (Acme Instant Dehydrated Boulder Kit)
- Newsgroups: comp.lang.c++
- Subject: Re: Is it OK to delete const *type pointers?
- Date: 12 Apr 1996 14:15:36 -0400
- Organization: Cloud-Zero, Canada
- Message-ID: <4km6k8$u0v@mag1.magmacom.com>
- References: <4k9g7c$fl9@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: mag1.magmacom.com
-
- In article <4k9g7c$fl9@arl-news-svc-5.compuserve.com>,
- Philippe Verdy <100105.3120@compuserve.com> wrote:
- ]Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> s'Θcrit :
- ]> Acme Instant Dehydrated Boulder Kit wrote:
- ]> >
- ]> > Some compilers let me do this, others do not. What I would like to know is,
- ]> > what does Stroustrup think? I.e. is it written somewhere in the ARM (I checked
- ]> > but can't find it) or in the draft standard? If somoene could e-mail me a
- ]> > quote or a pointer to a place where I can read where it says such a thing
- ]> > should or should not be allowed, I would appreciate it!
- ]> >
- ]> > const int* array= new int[30];
- ]> > delete[] array;
- ]> >
- ]> > MSVC says "can not delete const*"
- ]> > Some versions of G++ also don't let me do this.
- ]> >
- ]> > Is deleting an object technically considered changing that object's value?
- ]> >
- ]
- ]The following compiles under BC++ 4.0, 4.5, and 5.0:
- ]int const *ptr = new int(1);
- ]int const *arr = new int[10];
- ]main()
- ]{
- ] delete ptr;
- ] delete[] arr;
- ]}
- ]
- ]Being const does not mean the object is read-only. Nor does
-
- Your example demonstrates something completely different from mine.
- I was talking about const * type, or a pointer to a constant
- object. you are talking about type * const...
-
-
- ]it mean that its value won't change. Nor does it mean that
- ]it cannot be deleted.
-
- Deleting a type*const pointer makes total sense. i understand that.
-
- What I didn't understand (but do now) is whether one should be able to
- delete an object which is pointed to by a "pointer to constant object",
- because i feel that deleting an object changes its value, and when one
- returns a pointer to a constant object from a function, the calling block
- should not be able to delete the object through that pointer.
-
- But after posting to comp.lang.c++.moderated, i got a very good explanation.
- the gist of it was:
-
- 1. The ARM says you can't do it.
- 2. The draft standard as of november 1994 says you can.
-
- Therefore, in the future, new compilers will allow you to do this while old
- compilers will not. Any compiler which prevents you from deleting a const
- type* pointer does not conform to the draft standard.
-
-
- --
- Alan Ezust "Just because I work for the federal
- Ottawa, Canada government doesn't mean I'm an expert
- ezust@magmacom.com on cockroaches" -Special Agent Fox Mulder
- http://www2.magmacom.com/~ezust
-